<template>
  <div>
    <el-row type="flex" class="operate">
      <el-col>
        <el-button-group>
          <el-button v-if="show('add')" @click="add" type="primary">{{ config.root.add }}</el-button>
          <el-button v-if="show('deletes')" @click="deletes" type="danger">{{ config.root.dels }}</el-button>
          <!-- slot -->
          <slot name="left"></slot>
        </el-button-group>
      </el-col>
      <el-col class="tg-r">
        <el-button-group>
          <el-button v-if="show('screen')" @click="screen" :type="setScreen">{{ config.root.screen }} ( {{ num }} )</el-button>
          <el-button v-if="show('refresh')" @click="refresh" type="primary">{{ config.root.reset }}</el-button>
          <!-- slot -->
          <slot name="right"></slot>
        </el-button-group>
      </el-col>
    </el-row>
  </div>
</template>

<script>
  export default {
    props: {
      options: {
        type: Array,
        required: true
      },
      num: {
        type: [String, Number],
        required: false
      }
    },
    computed: {
      setScreen () {
        return this.num > 0 ? 'danger' : 'primary'
      }
    },
    methods: {
      // 判断是否显示选项
      show (val) {
        if (this.options) {
          return this.options.includes(val)
        }
      },
      // 新增
      add () {
        this.$emit('add')
      },
      // 批量删除
      deletes () {
        this.$emit('deletes')
      },
      // 刷新
      refresh () {
        this.$emit('refresh')
      },
      // 筛选
      screen () {
        this.$emit('screen')
      }
    }
  }
</script>

<style lang="scss" scoped>
  .operate {
    margin-bottom: 12px;
  }
</style>
